#include <iostream>
template<template<typename TT>  class Func, typename T>
void foreach(T array[], unsigned size)
{
    Func<T> func;
    for (unsigned i = 0; i < size; ++i) func(array[i]);
}
template<typename T>
struct inc
{
    void operator()(T &v) const {++v;}
};
template<typename T>
struct dec1
{
    void operator()(T &v) const {--v;}
};
template<typename T>
struct print
{
    void operator()(T &v) const {std::cout << ' ' << v;}
};
int main()
{
    using namespace std;
    int array[] = {1, 2, 3, 4, 5, 6, 7, 8};
    foreach<print>(array, 7); 
    cout << endl;

    foreach<inc>(array, 7);
    foreach<print>(array, 7);
    cout << endl;
    foreach<dec1>(array, 7);
    foreach<print>(array, 7);
    cout << endl;

    return 0;
}
